<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>Exported from Notepad++</title>
<style type="text/css">
span {
	font-family: 'Courier New';
	font-size: 10pt;
	color: #000000;
}
.sc0 {
}
.sc1 {
	font-style: italic;
	color: #0000FF;
}
.sc2 {
	font-style: italic;
	color: #0000FF;
}
.sc4 {
	color: #8000FF;
}
.sc5 {
	font-weight: bold;
	font-style: italic;
	color: #0000FF;
}
.sc6 {
	font-weight: bold;
	color: #008000;
}
.sc8 {
	font-weight: bold;
	font-style: italic;
	color: #008000;
}
.sc10 {
	font-weight: bold;
	color: #0080FF;
}
.sc11 {
}
.sc14 {
	color: #8080FF;
}
</style>
</head>
<body>
<div style="float: left; white-space: pre; line-height: 1; background: #FFFFFF; "><span class="sc2">// ========================================================= //</span><span class="sc0">
</span><span class="sc2">// =============== BOPWATCH.BPO : BEBOP 1.0 ================ //</span><span class="sc0">
</span><span class="sc2">// ========================================================= //</span><span class="sc0">

</span><span class="sc2">// compile with : bopbuild</span><span class="sc0">

</span><span class="sc1">/**
 * BOPWATCH.BPO : watching and debugging purpose
 * Implementation of the external tool "bopwatch"
 * @author Mathieu Barbin &lt;barbin@clipper.ens.fr&gt;
 * @date jeudi 3 juillet 2008, 12:56:30 (UTC+0200)
 */</span><span class="sc0">

</span><span class="sc2">// Set the source language : (version 1.0 ocaml only)</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">source</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc14">"ocaml"</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc6">init</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc8">Managment</span><span class="sc0"> </span><span class="sc11">of</span><span class="sc0"> </span><span class="sc5">external</span><span class="sc0"> </span><span class="sc11">process</span><span class="sc0"> </span><span class="sc5">with</span><span class="sc0"> </span><span class="sc11">send</span><span class="sc0"> </span><span class="sc6">and</span><span class="sc0"> </span><span class="sc6">pipe</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">send_process_table</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">ref</span><span class="sc0"> </span><span class="sc10">[];;</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">pipe_process_table</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">ref</span><span class="sc0"> </span><span class="sc10">[];;</span><span class="sc0">

</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc1">/*
    The method display wait a format-string ( "example %2b" )
    and signal-values to print.
*/</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc6">method</span><span class="sc0"> </span><span class="sc8">DISPLAY</span><span class="sc0"> </span><span class="sc10">[</span><span class="sc11">format</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc10">:[</span><span class="sc11">?</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">)</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">try</span><span class="sc0">
        </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Display</span><span class="sc10">.</span><span class="sc11">sprintf</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
        </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc8">For</span><span class="sc0"> </span><span class="sc11">example</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">print</span><span class="sc0"> </span><span class="sc11">the</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
        </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"%s\n"</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0">
    </span><span class="sc5">with</span><span class="sc0">
     </span><span class="sc10">|</span><span class="sc0"> </span><span class="sc8">Display</span><span class="sc10">.</span><span class="sc8">FormatError</span><span class="sc0"> </span><span class="sc11">message</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0">
        </span><span class="sc11">begin</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] BopWatch.display\n"</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Get   : \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">" %s\n"</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_string</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc10">);</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Error : \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">"\n"</span><span class="sc0"> </span><span class="sc11">message</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0">
        </span><span class="sc5">end</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">
</span><span class="sc1">/*
#method view [format] ( argv:[?] ) = ()
#with code %{

}%
*/</span><span class="sc0">

</span><span class="sc1">/*
    Method send : open a new process (if not made yet), and send message raither than printing 
    them on stderr 
*/</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc6">method</span><span class="sc0"> </span><span class="sc8">SEND</span><span class="sc0"> </span><span class="sc10">[</span><span class="sc11">process_command</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc10">[</span><span class="sc4">0</span><span class="sc10">..</span><span class="sc11">?</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">oc_send</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0">
        </span><span class="sc11">try</span><span class="sc0">
            </span><span class="sc8">List</span><span class="sc10">.</span><span class="sc11">assoc</span><span class="sc0"> </span><span class="sc11">process_command</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">!send_process_table</span><span class="sc10">)</span><span class="sc0">
        </span><span class="sc5">with</span><span class="sc0">
        </span><span class="sc10">|</span><span class="sc0"> </span><span class="sc8">Not_found</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0">
            </span><span class="sc11">begin</span><span class="sc0">
                </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">oc_tmp</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Unix</span><span class="sc10">.</span><span class="sc11">open_process_out</span><span class="sc0"> </span><span class="sc11">process_command</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
                </span><span class="sc11">send_process_table</span><span class="sc0"> </span><span class="sc10">:=</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">process_command</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">oc_tmp</span><span class="sc10">)::(</span><span class="sc11">!send_process_table</span><span class="sc10">);</span><span class="sc0">
                </span><span class="sc11">oc_tmp</span><span class="sc0">
            </span><span class="sc5">end</span><span class="sc0">
    </span><span class="sc11">in</span><span class="sc0">
    </span><span class="sc11">try</span><span class="sc0">
        </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Display</span><span class="sc10">.</span><span class="sc11">sprintf</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
        </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc8">For</span><span class="sc0"> </span><span class="sc11">example</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">print</span><span class="sc0"> </span><span class="sc11">the</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
        </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">oc_send</span><span class="sc0"> </span><span class="sc14">"%s\n"</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">oc_send</span><span class="sc0">
    </span><span class="sc5">with</span><span class="sc0">
     </span><span class="sc10">|</span><span class="sc0"> </span><span class="sc8">End_of_file</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0"> 
        </span><span class="sc11">begin</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Process \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">" is not responding\n"</span><span class="sc0"> </span><span class="sc11">process_command</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0">
        </span><span class="sc5">end</span><span class="sc0">
     </span><span class="sc10">|</span><span class="sc0"> </span><span class="sc8">Display</span><span class="sc10">.</span><span class="sc8">FormatError</span><span class="sc0"> </span><span class="sc11">message</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0">
        </span><span class="sc11">begin</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] BopWatch.display\n"</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Get   : \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">" %s\n"</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_string</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc10">);</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Error : \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">"\n"</span><span class="sc0"> </span><span class="sc11">message</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0">
        </span><span class="sc5">end</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc1">/*
    Method pipe : open a new process (if not made yet), and send message raither than printing 
    them on stderr , and read the answer, to make an echo of it
*/</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc6">method</span><span class="sc0"> </span><span class="sc8">WPIPE</span><span class="sc0"> </span><span class="sc10">[</span><span class="sc11">process_command</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc10">[</span><span class="sc4">0</span><span class="sc10">..</span><span class="sc11">?</span><span class="sc10">]</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">?</span><span class="sc0"> </span><span class="sc2">// free protocole</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">ic_pipe</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">oc_pipe</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0">
        </span><span class="sc11">try</span><span class="sc0">
            </span><span class="sc8">List</span><span class="sc10">.</span><span class="sc11">assoc</span><span class="sc0"> </span><span class="sc11">process_command</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">!pipe_process_table</span><span class="sc10">)</span><span class="sc0">
        </span><span class="sc5">with</span><span class="sc0">
        </span><span class="sc10">|</span><span class="sc0"> </span><span class="sc8">Not_found</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0">
            </span><span class="sc11">begin</span><span class="sc0">
                </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">ic_tmp</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">oc_tmp</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Unix</span><span class="sc10">.</span><span class="sc11">open_process</span><span class="sc0"> </span><span class="sc11">process_command</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
                </span><span class="sc11">pipe_process_table</span><span class="sc0"> </span><span class="sc10">:=</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">process_command</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">ic_tmp</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">oc_tmp</span><span class="sc10">))::(</span><span class="sc11">!pipe_process_table</span><span class="sc10">);</span><span class="sc0">
                </span><span class="sc10">(</span><span class="sc11">ic_tmp</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">oc_tmp</span><span class="sc10">)</span><span class="sc0">
            </span><span class="sc5">end</span><span class="sc0">
    </span><span class="sc11">in</span><span class="sc0">
    </span><span class="sc11">try</span><span class="sc0">
        </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc8">Display</span><span class="sc10">.</span><span class="sc11">sprintf</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
        </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc8">For</span><span class="sc0"> </span><span class="sc11">example</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">print</span><span class="sc0"> </span><span class="sc11">the</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
        </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">oc_pipe</span><span class="sc0"> </span><span class="sc14">"%s\n"</span><span class="sc0"> </span><span class="sc6">log</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">oc_pipe</span><span class="sc10">;</span><span class="sc0">
        </span><span class="sc11">print_endline</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">input_line</span><span class="sc0"> </span><span class="sc11">ic_pipe</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc5">with</span><span class="sc0">
     </span><span class="sc10">|</span><span class="sc0"> </span><span class="sc8">End_of_file</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0"> 
        </span><span class="sc11">begin</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Process \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">" is not responding\n"</span><span class="sc0"> </span><span class="sc11">process_command</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0">
        </span><span class="sc5">end</span><span class="sc0">
     </span><span class="sc10">|</span><span class="sc0"> </span><span class="sc8">Display</span><span class="sc10">.</span><span class="sc8">FormatError</span><span class="sc0"> </span><span class="sc11">message</span><span class="sc0"> </span><span class="sc10">-&gt;</span><span class="sc0">
        </span><span class="sc11">begin</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] BopWatch.display\n"</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Get   : \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">" %s\n"</span><span class="sc0"> </span><span class="sc11">format</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc8">BoolArray</span><span class="sc10">.</span><span class="sc11">to_string</span><span class="sc0"> </span><span class="sc11">argv</span><span class="sc10">);</span><span class="sc0">
            </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"[!] Error : \"</span><span class="sc10">%</span><span class="sc11">s\</span><span class="sc14">"\n"</span><span class="sc0"> </span><span class="sc11">message</span><span class="sc10">;</span><span class="sc0">
            </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0">
        </span><span class="sc5">end</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">



</span><span class="sc10">#</span><span class="sc11">main</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc8">Printf</span><span class="sc10">.</span><span class="sc11">fprintf</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc0"> </span><span class="sc14">"BopWatch : the main method does nothing\n"</span><span class="sc10">;</span><span class="sc0">
    </span><span class="sc11">flush</span><span class="sc0"> </span><span class="sc11">stderr</span><span class="sc10">;</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">
</span></div></body>
</html>
